package com.czk.gulimall.cart.vo;

import java.math.BigDecimal;
import java.util.List;

/**
 * 购物车vo
 *
 * @Author:ChenZhangKun
 * @Date: 2022/3/14 21:02
 */
public class Cart {
    List<CartItem> items;
    /**
     * 数量
     */
    private Integer countNum;
    /**
     * 类型
     */
    private Integer countType;
    /**
     * 总价
     */
    private BigDecimal totalAmount;
    /**
     * 优惠额
     */
    private BigDecimal reduce = new BigDecimal(0);

    public List<CartItem> getItems() {
        return items;
    }

    public void setItems(List<CartItem> items) {
        this.items = items;
    }

    public Integer getCountNum() {
        this.countNum = 0;
        if (items != null && items.size() > 0) {
            for (CartItem item : items) {
                countNum += item.getCount();
            }
        }
        return countNum;
    }


    public Integer getCountType() {
        this.countType = 0;
        if (items != null && items.size() > 0) {
            for (CartItem item : items) {
                countType += 1;
            }
        }
        return countType;
    }


    public BigDecimal getTotalAmount() {
        BigDecimal amount = new BigDecimal("0");
        if (items != null && items.size() > 0) {
            for (CartItem item : items) {
                if (item.getCheck()){
                    BigDecimal totalPrice = item.getTotalPrice();
                    // 相加
                    amount = amount.add(totalPrice);
                }

            }
        }
        // 减去优惠
        BigDecimal subtract = amount.subtract(getReduce());
        return subtract;
    }


    public BigDecimal getReduce() {
        return reduce;
    }

    public void setReduce(BigDecimal reduce) {
        this.reduce = reduce;
    }
}
